package com.pesking.core.sqlparser.processor;

import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.pesking.core.exception.SystemException;
import com.pesking.core.parameter.Parameter;
import com.pesking.core.sqlparser.parameter.SqlParameter;
import com.pesking.core.sqlparser.parameter.SqlParameterProcessor;
import com.pesking.core.util.SecurityUtils;

public class PasswordParameterSqlHandler extends SqlParameterProcessor {


	@Override
	public List<String> getSqlParameterType() {
		return Arrays.asList(new String []{"PWD","PASSWORD"});
	}

	@Override
	public int getOrder() {
		return 0;
	}

	@Override
	public void handle(StringBuilder sbSQL, Parameter parameter,List<SqlParameter> processors,SqlParameter sqlParameter) {
		String password = parameter.getParameter(sqlParameter.getName());
		if (StringUtils.isBlank(password)) {
			throw new SystemException("从请求参数对象中提取密码为空");
		}
		password = SecurityUtils.password(password);
		sbSQL.append("'").append(password).append("'");
	}
	
//	public static void main(String []args) {
//		System.out.println(SecurityUtils.password("7c4a8d09ca3762af61e59520943dc26494f8941b"));
//	}
}
